package com.stx.blog.action;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.service.ArticleService;
import com.stx.blog.service.UserService;
import com.stx.blog.vo.ArticleVo;
import com.stx.blog.vo.UserVo;

public class LoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3005415532143140893L;
	
	private UserVo uv=null;
	private UserService us;
	private ArticleService as;
	private ArticleVo av;
	private List<ArticleVo> articleList=new ArrayList<ArticleVo>();
	
	public ArticleService getAs() {
		return as;
	}

	public void setAs(ArticleService as) {
		this.as = as;
	}

	public ArticleVo getAv() {
		return av;
	}

	public void setAv(ArticleVo av) {
		this.av = av;
	}

	
	
	public List<ArticleVo> getArticleList() {
		return articleList;
	}

	public void setArticleList(List<ArticleVo> articleList) {
		this.articleList = articleList;
	}

	public UserVo getUv() {
		return uv;
	}

	public void setUv(UserVo uv) {
		this.uv = uv;
	}
	
	public UserService getUs() {
		return us;
	}

	public void setUs(UserService us) {
		this.us = us;
	}

	//注册用户登陆
	public String loginUser(){
		try{
			if(null==us.getUser(uv)){
				addActionError("邮箱名名或密码错误，请重新输入");
				return "input";
			}
			uv=us.getUser(uv);
            //得到此用户的博文list
			articleList=as.findArticle(uv);
			ServletActionContext.getRequest().getSession().setAttribute("user", uv);
			return "success";
		}catch(Exception e){
			e.printStackTrace();
			addActionError("联系管理员，出异常了");
			return "input";
		}
	}
	
}
